Dart.Ssh Namespace > SshConnection Class > Authenticate Method : Authenticate(String,String[]) Method |
'Declaration Public Overloads Sub Authenticate( _ ByVal username As String, _ ByVal submethods() As String _ )
'Usage Dim instance As SshConnection Dim username As String Dim submethods() As String instance.Authenticate(username, submethods)
public void Authenticate( string username, string[] submethods )
public: void Authenticate( string* username, string*[]* submethods )
public: void Authenticate( String^ username, array<String^>^ submethods )
Exception | Description |
---|---|
System.Security.Authentication.AuthenticationException | Authentication was unsuccessful. The server does not support this authentication method, or the arguments or challenge response(s) are invalid. |
Server interpretation of submethods is implementation-dependent. See RFC 4256 for more details.
Challenge will be raised with challenges generated by the server. Responses provided in your handler are sent back to the server. The challenge event can be raised more than once during the invocation of this method (e.g., if the server replies to the response with another challenge...).
Note: Some SSH servers advertise 'keyboard-interactive' but will deny its use.
The technique used to invoke this method is dependent upon the value of ThreadingModel. If ThreadingModel.Free, this method executes on the current thread and returns when complete (this is standard for creating applications in multi-threading environments like .NET). If ThreadingModel.ApartmentBlocking, this method blocks and processes windows UI messages while a worker thread executes (this is useful for making a simple blocking call in an apartment model environment like VB6). If ThreadingModel.ApartmentAsync, this method immediately returns after starting a worker thread that executes asynchronously (this is useful for creating advanced communications applications in an apartment model environment like VB6). The StateChanged event will be raised upon completion, or the Error event raised if an exception is thrown.
To support multi-factor authentication, the value of State can be checked after this method completes. If it returns ConnectionState.ConnectedAndPartiallyAuthenticated, further authentication is required and Connection.GetRemainingAuthMethods can be checked for a list of authentication methods that the server will accept as the subsequent authentication factor.
private void button1_Click(object sender, System.EventArgs e) { //Connect to the server ssh1.Connection.RemoteEndPoint.HostNameOrAddress = myServerHostname; ssh1.Connection.RemoteEndPoint.Port = myServerPort; //Usually 22 ssh1.Connect(); ssh1.Authenticate(myUsername, new string[] { }); } private void ssh1_Challenge(object sender, ChallengeEventArgs e) { for (int i = 0; i <= e.Prompt.Length - 1; i++) { if (e.Prompt[i] == "password:") e.Response[i] = myPassword; //If the server presents additional challenges, populate each response here } }
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click 'Connect to the server ssh1.Connection.RemoteEndPoint.HostNameOrAddress = myServerHostname ssh1.Connection.RemoteEndPoint.Port = myServerPort 'Usually 22 ssh1.Connect() ssh1.Authenticate(myUsername, New String() { }) End Sub Private Sub ssh1_Challenge(ByVal sender As Object, ByVal e As ChallengeEventArgs) Handles ssh1.Challenge For i As Integer = 0 To e.Prompt.Length - 1 If e.Prompt(i) = "password:" Then e.Response(i) = myPassword End If 'If the server presents additional challenges, populate each response here Next i End Sub